//获取分类列表
import request from '@/utils/request'
import type { CategoryVO } from '@/types/vo/CategoryVO'
import type { CategoryDTO } from '@/types/dto/CategoryDTO'
import type { LabelDTO } from '@/types/dto/LabelDTO'
import type { ArticleDTO } from '@/types/dto/ArticleDTO'
import type { Result } from '@/types/common/Result'
import type { ArticleVO } from '@/types/vo/ArticleVO'
import type { PageResult } from '@/types/common/PageResult'
import type { ArticleQuery } from '@/types/query/ArticleQuery'
import type {LabelVO} from "@/types/vo/LabelVO";

export const getCategoryList = (params: CategoryDTO) => {
  return request.post<Result<CategoryVO[]>>(`/article/category/list`, params)
}

/**
 *
 * @param params
 */
export function getLabelList(params: LabelDTO) {
  return request.post(`/article/label/list`, params)
}

/**
 * 上传文章
 * @param params
 */
export function publishArticle(params: ArticleDTO) {
  return request.post<Result<any>>(`/article/add`, params)
}

/**
 * 获取我的文章
 * @param params
 */
export function getMyArticleList(params: ArticleQuery) {
  return request.post<Result<PageResult<ArticleVO>>>(
    `/article/myArticle`,
    params,
  )
}

/**
 * 删除文章
 */
export const deleteArticleByIds = (ids: string) => {
  return request.delete<Result<any>>(`/article/delete/${ids}`);
}

/**
 * 获取文章详情
 * @param id
 */
export function getArticleDetail(id:number) {
  return request.get<Result<ArticleVO>>(`/article/${id}`);
}

/**
 * 修改文章
 * @param params
 */
export function updateArticle(params: ArticleDTO) {
  return request.post<Result<any>>(`/article/update`, params);
}

// 新增分类
export function addCategory(params: CategoryDTO) {
  return request.post<Result<any>>(`/article/category/add`, params);
}

// 获取分类详情
export function getCategoryDetail(id: number) {
  return request.get<Result<CategoryVO>>(`/article/category/${id}`);
}

// 修改分类
export function updateCategory(params: CategoryDTO) {
  return request.put<Result<any>>(`/article/category/update`, params);
}

// 删除分类
export function deleteCategoryByIds(ids: string) {
  return request.delete<Result<any>>(`/article/category/delete/${ids}`);
}

// 新增标签
export function addLabel(params: LabelDTO) {
  return request.post<Result<any>>(`/article/label/add`, params);
}

// 获取标签详情
export function getLabelDetail(id: number) {
  return request.get<Result<LabelVO>>(`/article/label/${id}`);
}

// 修改标签
export function updateLabel(params: LabelDTO) {
  return request.put<Result<any>>(`/article/label/update`, params);
}

// 删除标签
export function deleteLabelByIds(ids: string) {
  return request.delete<Result<any>>(`/article/label/delete/${ids}`);
}
